package com.yy.bolg.service.impl;

import com.yy.bolg.dao.RepairDao;
import com.yy.bolg.dao.TestingDao;
import com.yy.bolg.entity.RepairBean;
import com.yy.bolg.entity.TestingBean;
import com.yy.bolg.exception.LackParameterException;
import com.yy.bolg.exception.OtherThingsException;
import com.yy.bolg.service.RepairService;
import com.yy.bolg.service.TestingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 检测Service实现类，对接口里的方法进行构造填充
 * @author enmaoFu
 * @date 2024-11-12
 */
@Service("repairService")
public class RepairServiceImpl implements RepairService {

    @Autowired
    private RepairDao repairDao;

    @Override
    public void add(RepairBean bean) throws Exception {
        if(StringUtils.isEmpty(bean.getPsRepairCode())){
            throw new LackParameterException("维修编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsCustomerCode())){
            throw new LackParameterException("客户（单位）编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsFeedbackCode())){
            throw new LackParameterException("上报编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsWorkOrderCode())){
            throw new LackParameterException("工单编号不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsRepairContent())){
            throw new LackParameterException("维修描述不能为空");
        }

        if(StringUtils.isEmpty(bean.getPsRepairImgFile())){
            throw new LackParameterException("维修图片不能为空");
        }

        try {
            repairDao.add(bean);
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("添加数据失败");
        }
    }

    @Override
    public RepairBean findOneByCode(RepairBean bean) throws Exception {
        if (StringUtils.isEmpty(bean.getPsRepairCode())) {
            throw new LackParameterException("维修编号不能为空");
        }

        try {
            return repairDao.findOneByCode(bean.getPsRepairCode());
        } catch (Exception e) {
            e.printStackTrace();
            throw new OtherThingsException("暂无数据");
        }
    }
}
